package db;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.*;

public class DBConnection {
    private static final ComboPooledDataSource DS = new ComboPooledDataSource();

    public static ComboPooledDataSource getDs() {
        return DS;
    }

    public static Connection getConnection() {
        Connection connection = null;
        try {
            connection = DS.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }


    public static void close(Connection conn, Statement stat, ResultSet rs){
        try {

            if(conn != null){
                conn.close();
            }

            if(stat != null){
                stat.close();
            }

            if(rs != null){
                rs.close();
            }
        }catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
